﻿@model Kooboo.CMS.Sites.Models.Page
@{
    ViewBag.Title = "New page".Localize();
    Layout = "~/Views/Shared/Blank.cshtml";
    var publishPermission = ServiceFactory.UserManager.Authorize(Kooboo.CMS.Sites.Models.Site.Current, ViewContext.HttpContext.User.Identity.Name, Kooboo.CMS.Account.Models.Permission.Sites_Page_PublishPermission);
}
@section Panel{
    <ul class="panel">
        @if (publishPermission)
        {
            <li class="j_DropDown">
                <a>
                    @Html.IconImage("save")
                    @Html.IconImage("arrow small white-down")
                    @("Save".Localize())
                </a>
                <ul class="j_DropDownContent hide">
                    <li><a data-ajaxform="" id="save_bar">@("Save".Localize())</a></li>
                    <li><a data-ajaxform=""  href="@Url.Action("CreateEx", "Page", ViewContext.RequestContext.AllRouteValues().Merge("setPublished", "true"))">@("Save & publish".Localize())</a></li>
                </ul>
            </li>
        }
        else
        {
            <li><a data-ajaxform="">@Html.IconImage("save") @("Save".Localize())</a></li>
        }
        @foreach (var group in Kooboo.CMS.Sites.Extension.UI.TopToolbar.ToolbarButtons.GetToolbarButtons(ViewContext.RequestContext))
        {
            @Html.Partial("_ToolbarGroupButtons", group)
        }
        <li><a href="@ViewContext.RequestContext.GetRequestValue("return")">@Html.IconImage("cancel") @("Back".Localize())</a></li>
    </ul>
}

<div class="block common-form">
    @using (Html.BeginForm("CreateEx", "Page", ViewContext.RequestContext.AllRouteValues(), FormMethod.Post, new RouteValueDictionary(new { id = "page-form" })))
    {
        @Html.Hidden("SiteName", ViewContext.RequestContext.GetRequestValue("SiteName")) 
        @Html.Hidden("ParentPage", ViewContext.RequestContext.GetRequestValue("ParentPage"))
        @Html.ValidationSummary(true)
        <h1 class="title left">@ViewBag.Title:</h1>
        <p class="field big clearfix">
            @Html.EditorFor(m => m.Name, new { Layout = "_NoLabel.cshtml" })
        </p>
        @Html.Partial("_PageTabs", Model, new ViewDataDictionary() { { "IsCreating", true } })
    }
</div>

<script type="text/javascript">
    $(function () {
        $('.tabs').koobooTab();
        var enableScript = $('#EnableScript').change(function () {
            var handler = $(this);
            if (!handler.attr('checked')) {
                enableJquery.attr('checked', false).attr('disabled', true);
            } else {
                enableJquery.removeAttr('disabled');
            }
        });

        var enableJquery = $('#EnableJquery').change(function () {
            var hanlder = $(this);
            if (hanlder.attr('checked')) {
                enableScript.attr('checked', true);
            }
        });


        if (!enableScript.attr('checked')) {
            enableJquery.attr('checked', false).attr('disabled', true);
        } else {
            enableJquery.removeAttr('disabled');
        }

    });
</script>
